home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / perl5 / Glib / xsapi.pod < prev   
Encoding:
Text File  |  2007-03-05  |  36.7 KB  |  1,132 lines

  1.  
  2. =head1 NAME
  3.  
  4. Glib::xsapi - internal API reference for GPerl.
  5.  
  6. =head1 SYNOPSIS
  7.  
  8.  #include <gperl.h>
  9.  
  10. =head1 DESCRIPTION
  11.  
  12. This is the binding developer's API reference for GPerl, automatically
  13. generated from the xs source files.  This header defines the public
  14. interface for use when creating new Perl language bindings for GLib-based C
  15. libraries.
  16.  
  17. gperl.h includes for you all the headers needed for writing XSUBs 
  18. (EXTERN.h, perl.h, and XSUB.h), as well as all of GLib (via glib-object.h).
  19.  
  20. =head1 API
  21.  
  22. =cut
  23.  
  24. =head2 Miscellaneous
  25.  
  26. Various useful utilities defined in Glib.xs.
  27.  
  28. =over
  29.  
  30. =cut
  31.  
  32. =item GPERL_CALL_BOOT(name)
  33.  
  34. call the boot code of a module by symbol rather than by name.
  35.  
  36. in a perl extension which uses several xs files but only one pm, you
  37. need to bootstrap the other xs files in order to get their functions
  38. exported to perl.  if the file has MODULE = Foo::Bar, the boot symbol
  39. would be boot_Foo__Bar.
  40.  
  41. =item void _gperl_call_XS (pTHX_ void (*subaddr) (pTHX_ CV *), CV * cv, SV ** mark);
  42.  
  43. never use this function directly.  see C<GPERL_CALL_BOOT>.
  44.  
  45. for the curious, this calls a perl sub by function pointer rather than
  46. by name; call_sv requires that the xsub already be registered, but we
  47. need this to call a function which will register xsubs.  this is an
  48. evil hack and should not be used outside of the GPERL_CALL_BOOT macro.
  49. it's implemented as a function to avoid code size bloat, and exported
  50. so that extension modules can pull the same trick.
  51.  
  52. =cut
  53.  
  54. =item gpointer gperl_alloc_temp (int nbytes)
  55.  
  56. Allocate and return a pointer to an I<nbytes>-long, zero-initialized,
  57. temporary buffer that will be reaped at the next garbage collection sweep.
  58. This is handy for allocating things that need to be alloc'ed before a croak
  59. (since croak doesn't return and give you the chance to free them).  The
  60. trick is that the memory is allocated in a mortal perl scalar.  See the
  61. perl online manual for notes on using this technique.
  62.  
  63. Do B<not> under any circumstances attempt to call g_free(), free(), or any
  64. other deallocator on this pointer, or you will crash the interpreter.
  65.  
  66. =cut
  67.  
  68. =item gchar *gperl_filename_from_sv (SV *sv)
  69.  
  70. Return a localized version of the filename in the sv, using
  71. g_filename_from_utf8 (and consequently this function might croak). The
  72. memory is allocated using gperl_alloc_temp.
  73.  
  74. =cut
  75.  
  76. =item SV *gperl_sv_from_filename (const gchar *filename)
  77.  
  78. Convert the filename into an utf8 string as used by gtk/glib and perl.
  79.  
  80. =cut
  81.  
  82. =item gboolean gperl_str_eq (const char * a, const char * b);
  83.  
  84. Compare a pair of ascii strings, considering '-' and '_' to be equivalent.
  85. Used for things like enum value nicknames and signal names.
  86.  
  87. =cut
  88.  
  89. =item guint gperl_str_hash (gconstpointer key)
  90.  
  91. Like g_str_hash(), but considers '-' and '_' to be equivalent.
  92.  
  93. =cut
  94.  
  95. =item GPerlArgv * gperl_argv_new ()
  96.  
  97. Creates a new Perl argv object whose members can then be passed to functions
  98. that request argc and argv style arguments.
  99.  
  100. If the called function(s) modified argv, you can call L<gperl_argv_update> to
  101. update Perl's @ARGV in the same way.
  102.  
  103. Remember to call L<gperl_argv_free> when you're done.
  104.  
  105. =cut
  106.  
  107. =item void gperl_argv_update (GPerlArgv *pargv)
  108.  
  109. Updates @ARGV to resemble the stored argv array.
  110.  
  111. =cut
  112.  
  113. =item void gperl_argv_free (GPerlArgv *pargv)
  114.  
  115. Frees any resources associated with I<pargv>.
  116.  
  117. =cut
  118.  
  119. =item char * gperl_format_variable_for_output (SV * sv)
  120.  
  121. Formats the variable stored in I<sv> for output in error messages.  Like
  122. SvPV_nolen(), but ellipsizes real strings (i.e., not stringified references)
  123. at 20 chars to trim things down for error messages.
  124.  
  125. =cut
  126.  
  127. =back
  128.  
  129. =cut
  130.  
  131. =head2 GError Exception Objects
  132.  
  133. GError is a facility for propagating run-time error / exception information
  134. around in C, which is a language without native support for exceptions.
  135. GError uses a simple error code, usually defined as an enum.  Since the
  136. enums will overlap, GError includes the GQuark corresponding to a particular
  137. error "domain" to tell you which error codes will be used.  There's also a
  138. string containing a specific error message.  The strings are arbitrary, and
  139. may be translated, but the domains and codes are definite.
  140.  
  141. Perl has native support for exceptions, using C<eval> as "try", C<croak> or
  142. C<die> as "throw", and C<< if ($@) >> as "catch".  C<$@> may, in fact, be
  143. any scalar, including blessed objects.
  144.  
  145. So, GPerl maps GLib's GError to Perl exceptions.
  146.  
  147. Since, as we described above, error messages are not guaranteed to be unique
  148. everywhere, we need to support the use of the error domains and codes.
  149. The obvious choice here is to use exception objects; however, to support
  150. blessed exception objects, we must perform a little bit of black magic in
  151. the bindings.   There is no built-in association between an error domain
  152. quark and the GType of the corresponding error code enumeration, so the
  153. bindings supply both of these when specifying the name of the package into
  154. which to bless exceptions of this domain.  All GError-based exceptions 
  155. derive from Glib::Error, of course, and this base class provides all of the
  156. functionality, including stringification.
  157.  
  158. All you'll really ever need to do is register error domains with
  159. C<gperl_register_error_domain>, and throw errors with C<gperl_croak_gerror>.
  160.  
  161. =over
  162.  
  163. =cut
  164.  
  165. =item void gperl_register_error_domain (GQuark domain, GType error_enum, const char * package)
  166.  
  167. Tell the bindings to bless GErrors with error->domain == I<domain> into
  168. I<package>, and use I<error_enum> to find the nicknames for the error codes.
  169. This will call C<gperl_set_isa> on I<package> to add "Glib::Error" to
  170. I<package>'s @ISA.
  171.  
  172. I<domain> may not be 0, and I<package> may not be NULL; what would be the 
  173. point?  I<error_enum> may be 0, in which case you'll get no fancy stringified
  174. error values.
  175.  
  176. =cut
  177.  
  178. =item SV * gperl_sv_from_gerror (GError * error)
  179.  
  180. You should rarely, if ever, need to call this function.  This is what turns
  181. a GError into a Perl object.
  182.  
  183. =cut
  184.  
  185. =item gperl_gerror_from_sv (SV * sv, GError ** error)
  186.  
  187. You should rarely need this function.  This parses a perl data structure into
  188. a GError.  If I<sv> is undef (or the empty string), sets *I<error> to NULL,
  189. otherwise, allocates a new GError with C<g_error_new_literal()> and writes
  190. through I<error>; the caller is responsible for calling C<g_error_free()>.
  191. (gperl_croak_gerror() does this, for example.)
  192.  
  193. =cut
  194.  
  195. =item void gperl_croak_gerror (const char * ignored, GError * err)
  196.  
  197. Croak with an exception based on I<err>.  I<err> may not be NULL.  I<ignored>
  198. exists for backward compatibility, and is, well, ignored.  This function
  199. calls croak(), which does not return.
  200.  
  201. Since croak() does not return, this function handles the magic behind 
  202. not leaking the memory associated with the #GError.  To use this you'd
  203. do something like
  204.  
  205.  PREINIT:
  206.    GError * error = NULL;
  207.  CODE:
  208.    if (!funtion_that_can_fail (something, &error))
  209.       gperl_croak_gerror (NULL, error);
  210.  
  211. It's just that simple!
  212.  
  213. =cut
  214.  
  215. =back
  216.  
  217. =cut
  218.  
  219. =head2 GLog
  220.  
  221. GLib has a message logging mechanism which it uses for the g_return_if_fail()
  222. assertion macros, etc.; it's really versatile and allows you to set various
  223. levels to be fatal and whatnot.  Libraries use these for various types of
  224. message reporting.
  225.  
  226. These functions let you reroute those messages from Perl.  By default, 
  227. the warning, critical, and message levels go through perl's warn(), and
  228. fatal ones go through croak().  [i'm not sure that these get to croak()
  229. before GLib abort()s on them...]
  230.  
  231. =over
  232.  
  233. =cut
  234.  
  235. =item gint gperl_handle_logs_for (const gchar * log_domain)
  236.  
  237. Route all g_logs for I<log_domain> through gperl's log handling.  You'll
  238. have to register domains in each binding submodule, because there's no way
  239. we can know about them down here.
  240.  
  241. And, technically, this traps all the predefined log levels, not any of
  242. the ones you (or your library) may define for yourself.
  243.  
  244. =cut
  245.  
  246. =back
  247.  
  248. =cut
  249.  
  250. =head2 GType / GEnum / GFlags
  251.  
  252. =over
  253.  
  254. =cut
  255.  
  256. =item void gperl_register_fundamental (GType gtype, const char * package)
  257.  
  258. register a mapping between I<gtype> and I<package>.  this is for "fundamental"
  259. types which have no other requirements for metadata storage, such as GEnums,
  260. GFlags, or real GLib fundamental types like G_TYPE_INT, G_TYPE_FLOAT, etc.
  261.  
  262. =cut
  263.  
  264. =item GPerlValueWrapperClass
  265.  
  266. Specifies the vtable that is to be used to convert fundamental types to and
  267. from Perl variables.
  268.  
  269.   typedef struct _GPerlValueWrapperClass GPerlValueWrapperClass;
  270.   struct _GPerlValueWrapperClass {
  271.           GPerlValueWrapFunc   wrap;
  272.           GPerlValueUnwrapFunc unwrap;
  273.   };
  274.  
  275. The members are function pointers, each of which serves a specific purpose:
  276.  
  277. =over
  278.  
  279. =item GPerlValueWrapFunc
  280.  
  281. Turns I<value> into an SV.  The caller assumes ownership of the SV.  I<value>
  282. is not to be modified.
  283.  
  284.   typedef SV*  (*GPerlValueWrapFunc)   (const GValue * value);
  285.  
  286. =item GPerlValueUnwrapFunc
  287.  
  288. Turns I<sv> into its fundamental representation and stores the result in the
  289. pre-configured I<value>.  I<value> must not be overwritten; instead one of the
  290. various C<g_value_set_*()> functions must be used or the C<value-E<gt>data>
  291. pointer must be modifed directly.
  292.  
  293.   typedef void (*GPerlValueUnwrapFunc) (GValue       * value,
  294.                                         SV           * sv);
  295.  
  296. =back
  297.  
  298. =cut
  299.  
  300. =item void gperl_register_fundamental_full (GType gtype, const char * package, GPerlValueWrapperClass * wrapper_class)
  301.  
  302. Like L<gperl_register_fundamental>, registers a mapping between I<gtype> and
  303. I<package>.  In addition, this also installs the function pointers in
  304. I<wrapper_class> as the handlers for the type.  See L<GPerlValueWrapperClass>.
  305.  
  306. I<gperl_register_fundamental_full> does not copy the contents of
  307. I<wrapper_class> -- it assumes that I<wrapper_class> is statically allocated
  308. and that it will be valid for the whole lifetime of the program.
  309.  
  310. =cut
  311.  
  312. =item GType gperl_fundamental_type_from_package (const char * package)
  313.  
  314. look up the GType corresponding to a I<package> registered by
  315. gperl_register_fundamental().
  316.  
  317. =cut
  318.  
  319. =item const char * gperl_fundamental_package_from_type (GType gtype)
  320.  
  321. look up the package corresponding to a I<gtype> registered by
  322. gperl_register_fundamental().
  323.  
  324. =cut
  325.  
  326. =item GPerlValueWrapperClass * gperl_fundamental_wrapper_class_from_type (GType gtype)
  327.  
  328. look up the wrapper class corresponding to a I<gtype> that has previously been
  329. registered with gperl_register_fundamental_full().
  330.  
  331. =cut
  332.  
  333. =item gboolean gperl_try_convert_enum (GType gtype, SV * sv, gint * val)
  334.  
  335. return FALSE if I<sv> can't be mapped to a valid member of the registered
  336. enum type I<gtype>; otherwise, return TRUE write the new value to the
  337. int pointed to by I<val>.
  338.  
  339. you'll need this only in esoteric cases.
  340.  
  341. =cut
  342.  
  343. =item gint gperl_convert_enum (GType type, SV * val)
  344.  
  345. croak if I<val> is not part of I<type>, otherwise return corresponding value
  346.  
  347. =cut
  348.  
  349. =item SV * gperl_convert_back_enum_pass_unknown (GType type, gint val)
  350.  
  351. return a scalar containing the nickname of the enum value I<val>, or the
  352. integer value of I<val> if I<val> is not a member of the enum I<type>.
  353.  
  354. =cut
  355.  
  356. =item SV * gperl_convert_back_enum (GType type, gint val)
  357.  
  358. return a scalar which is the nickname of the enum value val, or croak if
  359. val is not a member of the enum.
  360.  
  361. =cut
  362.  
  363. =item gboolean gperl_try_convert_flag (GType type, const char * val_p, gint * val)
  364.  
  365. like gperl_try_convert_enum(), but for GFlags.
  366.  
  367. =cut
  368.  
  369. =item gint gperl_convert_flag_one (GType type, const char * val)
  370.  
  371. croak if I<val> is not part of I<type>, otherwise return corresponding value.
  372.  
  373. =cut
  374.  
  375. =item gint gperl_convert_flags (GType type, SV * val)
  376.  
  377. collapse a list of strings to an integer with all the correct bits set,
  378. croak if anything is invalid.
  379.  
  380. =cut
  381.  
  382. =item SV * gperl_convert_back_flags (GType type, gint val)
  383.  
  384. convert a bitfield to a list of strings.
  385.  
  386. =cut
  387.  
  388. =back
  389.  
  390. =head2 Inheritance management
  391.  
  392. =over
  393.  
  394. =item void gperl_set_isa (const char * child_package, const char * parent_package)
  395.  
  396. tell perl that I<child_package> inherits I<parent_package>, after whatever else
  397. is already there.  equivalent to C<< push @{$parent_package}::ISA, $child_package; >>
  398.  
  399. =cut
  400.  
  401. =item void gperl_prepend_isa (const char * child_package, const char * parent_package)
  402.  
  403. tell perl that I<child_package> inherits I<parent_package>, but before whatever
  404. else is already there.  equivalent to C<< unshift @{$parent_package}::ISA, $child_package; >>
  405.  
  406. =cut
  407.  
  408. =item GType gperl_type_from_package (const char * package)
  409.  
  410. Look up the GType associated with I<package>, regardless of how it was
  411. registered.  Returns 0 if no mapping can be found.
  412.  
  413. =cut
  414.  
  415. =item const char * gperl_package_from_type (GType gtype)
  416.  
  417. Look up the name of the package associated with I<gtype>, regardless of how it
  418. was registered.  Returns NULL if no mapping can be found.
  419.  
  420. =cut
  421.  
  422. =back
  423.  
  424. =head2 Boxed type support for SV
  425.  
  426. In order to allow GValues to hold perl SVs we need a GBoxed wrapper.
  427.  
  428. =over
  429.  
  430. =item GPERL_TYPE_SV
  431.  
  432. Evaluates to the GType for SVs.  The bindings register a mapping between
  433. GPERL_TYPE_SV and the package 'Glib::Scalar' with gperl_register_boxed().
  434.  
  435. =item SV * gperl_sv_copy (SV * sv)
  436.  
  437. implemented as C<< newSVsv (sv) >>.
  438.  
  439. =item void gperl_sv_free (SV * sv)
  440.  
  441. implemented as C<< SvREFCNT_dec (sv) >>.
  442.  
  443. =cut
  444.  
  445. =back
  446.  
  447. =head2 UTF-8 strings with gchar
  448.  
  449. By convention, gchar* is assumed to point to UTF8 string data,
  450. and char* points to ascii string data.  Here we define a pair of
  451. wrappers for the boilerplate of upgrading Perl strings.  They
  452. are implemented as functions rather than macros, because comma
  453. expressions in macros are not supported by all compilers.
  454.  
  455. These functions should be used instead of newSVpv and SvPV_nolen
  456. in all cases which deal with gchar* types.
  457.  
  458. =over
  459.  
  460. =item gchar * SvGChar (SV * sv)
  461.  
  462. extract a UTF8 string from I<sv>.
  463.  
  464. =cut
  465.  
  466. =item SV * newSVGChar (const gchar * str)
  467.  
  468. copy a UTF8 string into a new SV.  if str is NULL, returns &PL_sv_undef.
  469.  
  470. =cut
  471.  
  472. =back
  473.  
  474. =head2 64 bit integers
  475.  
  476. On 32 bit machines and even on some 64 bit machines, perl's IV/UV data type can
  477. only hold 32 bit values.  The following functions therefore convert 64 bit
  478. integers to and from Perl strings if normal IV/UV conversion does not suffice.
  479.  
  480. =over
  481.  
  482. =item gint64 SvGInt64 (SV *sv)
  483.  
  484. Converts the string in I<sv> to a signed 64 bit integer.  If appropriate, uses
  485. C<SvIV> instead.
  486.  
  487. =cut
  488.  
  489. =item SV * newSVGInt64 (gint64 value)
  490.  
  491. Creates a PV from the signed 64 bit integer in I<value>.  If appropriate, uses
  492. C<newSViv> instead.
  493.  
  494. =cut
  495.  
  496. =item guint64 SvGUInt64 (SV *sv)
  497.  
  498. Converts the string in I<sv> to an unsigned 64 bit integer.  If appropriate,
  499. uses C<SvUV> instead.
  500.  
  501. =cut
  502.  
  503. =item SV * newSVGUInt64 (guint64 value)
  504.  
  505. Creates a PV from the unsigned 64 bit integer in I<value>.  If appropriate,
  506. uses C<newSVuv> instead.
  507.  
  508. =cut
  509.  
  510. =back
  511.  
  512. =cut
  513.  
  514. =head2 GBoxed
  515.  
  516. =over
  517.  
  518. =item GPerlBoxedWrapperClass
  519.  
  520. Specifies the vtable of functions to be used for bringing boxed types in
  521. and out of perl.  The structure is defined like this:
  522.  
  523.  typedef struct _GPerlBoxedWrapperClass GPerlBoxedWrapperClass;
  524.  struct _GPerlBoxedWrapperClass {
  525.           GPerlBoxedWrapFunc    wrap;
  526.           GPerlBoxedUnwrapFunc  unwrap;
  527.           GPerlBoxedDestroyFunc destroy;
  528.  };
  529.  
  530. The members are function pointers, each of which serves a specific purpose:
  531.  
  532. =over
  533.  
  534. =item GPerlBoxedWrapFunc
  535.  
  536. turn a boxed pointer into an SV.  gtype is the type of the boxed pointer,
  537. and package is the package to which that gtype is registered (the lookup
  538. has already been done for you at this point).  if own is true, the wrapper
  539. is responsible for freeing the object; if it is false, some other code 
  540. owns the object and you must NOT free it.
  541.  
  542.  typedef SV*      (*GPerlBoxedWrapFunc)    (GType        gtype,
  543.                                             const char * package,
  544.                                             gpointer     boxed,
  545.                                             gboolean     own);
  546.  
  547. =item GPerlBoxedUnwrapFunc
  548.  
  549. turn an SV into a boxed pointer.  like GPerlBoxedWrapFunc, gtype and package
  550. are the registered type pair, already looked up for you (in the process of
  551. finding the proper wrapper class).  sv is the sv to unwrap.
  552.  
  553.  typedef gpointer (*GPerlBoxedUnwrapFunc)  (GType        gtype,
  554.                                             const char * package,
  555.                                             SV         * sv);
  556.  
  557. =item GPerlBoxedDestroyFunc
  558.  
  559. this will be called by Glib::Boxed::DESTROY, when the wrapper is destroyed.
  560. it is a hook that allows you to destroy an object owned by the wrapper;
  561. note, however, that you will have had to keep track yourself of whether
  562. the object was to be freed.
  563.  
  564.  typedef void     (*GPerlBoxedDestroyFunc) (SV         * sv);
  565.  
  566. =back
  567.  
  568. =cut
  569.  
  570. =item void gperl_register_boxed (GType gtype, const char * package, GPerlBoxedWrapperClass * wrapper_class)
  571.  
  572. Register a mapping between the GBoxed derivative I<gtype> and I<package>.  The
  573. specified, I<wrapper_class> will be used to wrap and unwrap objects of this
  574. type; you may pass NULL to use the default wrapper (the same one returned by
  575. gperl_default_boxed_wrapper_class()).
  576.  
  577. In normal usage, the standard opaque wrapper supplied by the library is
  578. sufficient and correct.  In some cases, however, you want a boxed type to map
  579. directly to a native perl type; for example, some struct may be more
  580. appropriately represented as a hash in perl.  Since the most necessary place
  581. for this conversion to happen is in gperl_value_from_sv() and
  582. gperl_sv_from_value(), the only reliable and robust way to implement this 
  583. is a hook into gperl_get_boxed_check() and gperl_new_boxed(); that is
  584. exactly the purpose of I<wrapper_class>.  See C<GPerlBoxedWrapperClass>.
  585.  
  586. I<gperl_register_boxed> does not copy the contents of I<wrapper_class> -- it
  587. assumes that I<wrapper_class> is statically allocated and that it will be valid
  588. for the whole lifetime of the program.
  589.  
  590. =cut
  591.  
  592. =item GType gperl_boxed_type_from_package (const char * package)
  593.  
  594. Look up the GType associated with package I<package>.  Returns 0 if I<type> is
  595. not registered.
  596.  
  597. =cut
  598.  
  599. =item const char * gperl_boxed_package_from_type (GType type)
  600.  
  601. Look up the package associated with GBoxed derivative I<type>.  Returns NULL if
  602. I<type> is not registered.
  603.  
  604. =cut
  605.  
  606. =item GPerlBoxedWrapperClass * gperl_default_boxed_wrapper_class (void)
  607.  
  608. get a pointer to the default wrapper class; handy if you want to use
  609. the normal wrapper, with minor modifications.  note that you can just
  610. pass NULL to gperl_register_boxed(), so you really only need this in
  611. fringe cases.
  612.  
  613. =cut
  614.  
  615. =item SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own)
  616.  
  617. Export a GBoxed derivative to perl, according to whatever
  618. GPerlBoxedWrapperClass is registered for I<gtype>.  In the default
  619. implementation, this means wrapping an opaque perl object around the pointer
  620. to a small wrapper structure which stores some metadata, such as whether
  621. the boxed structure should be destroyed when the wrapper is destroyed
  622. (controlled by I<own>; if the wrapper owns the object, the wrapper is in
  623. charge of destroying it's data).
  624.  
  625. =cut
  626.  
  627. =item SV * gperl_new_boxed_copy (gpointer boxed, GType gtype)
  628.  
  629. Create a new copy of I<boxed> and return an owner wrapper for it.
  630. I<boxed> may not be NULL.  See C<gperl_new_boxed>.
  631.  
  632. =cut
  633.  
  634. =item gpointer gperl_get_boxed_check (SV * sv, GType gtype)
  635.  
  636. Extract the boxed pointer from a wrapper; croaks if the wrapper I<sv> is not
  637. blessed into a derivative of the expected I<gtype>.  Does not allow undef.
  638.  
  639. =cut
  640.  
  641. =back
  642.  
  643. =cut
  644.  
  645. =head2 GObject
  646.  
  647. To deal with the intricate interaction of the different reference-counting
  648. semantics of Perl objects versus GObjects, the bindings create a combined
  649. PerlObject+GObject, with the GObject's pointer in magic attached to the Perl
  650. object, and the Perl object's pointer in the GObject's user data.  Thus it's
  651. not really a "wrapper", but we refer to it as one, because "combined Perl
  652. object + GObject" is a cumbersome and confusing mouthful.
  653.  
  654. GObjects are represented as blessed hash references.  The GObject user data
  655. mechanism is not typesafe, and thus is used only for unsigned integer values;
  656. the Perl-level hash is available for any type of user data.  The combined
  657. nature of the wrapper means that data stored in the hash will stick around as
  658. long as the object is alive.
  659.  
  660. Since the C pointer is stored in attached magic, the C pointer is not available
  661. to the Perl developer via the hash object, so there's no need to worry about
  662. breaking it from perl.
  663.  
  664. Propers go to Marc Lehmann for dreaming most of this up.
  665.  
  666. =over
  667.  
  668. =cut
  669.  
  670. =item void gperl_register_object (GType gtype, const char * package)
  671.  
  672. tell the GPerl type subsystem what Perl package corresponds with a given
  673. GObject by GType.  automagically sets up @I<package>::ISA for you.
  674.  
  675. note that @ISA will not be created for gtype until gtype's parent has
  676. been registered.  if you are experiencing strange problems with a class'
  677. @ISA not being set up, change the order in which you register them.
  678.  
  679. =cut
  680.  
  681. =item void gperl_register_sink_func (GType gtype, GPerlObjectSinkFunc func)
  682.  
  683. Tell gperl_new_object() to use I<func> to claim ownership of objects derived
  684. from I<gtype>.
  685.  
  686. gperl_new_object() always refs a GObject when wrapping it for the first time.
  687. To have the Perl wrapper claim ownership of a GObject as part of
  688. gperl_new_object(), you unref the object after ref'ing it. however, different
  689. GObject subclasses have different ways to claim ownership; for example,
  690. GtkObject simply requires you to call gtk_object_sink().  To make this concept
  691. generic, this function allows you to register a function to be called when then
  692. wrapper should claim ownership of the object.  The I<func> registered for a
  693. given I<type> will be called on any object for which C<< g_type_isa
  694. (G_TYPE_OBJECT (object), type) >> succeeds.
  695.  
  696. If no sinkfunc is found for an object, g_object_unref() will be used.
  697.  
  698. Even though GObjects don't need sink funcs, we need to have them in Glib
  699. as a hook for upstream objects.  If we create a GtkObject (or any
  700. other type of object which uses a different way to claim ownership) via
  701. Glib::Object->new, any upstream wrappers, such as gtk2perl_new_object(), will
  702. B<not> be called.  Having a sink func facility down here enables us always to
  703. do the right thing.
  704.  
  705. =cut
  706.  
  707. =item void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn)
  708.  
  709. In versions 1.00 through 1.10x of Glib, the bindings required all types
  710. to be registered ahead of time.  Upon encountering an unknown type, the
  711. bindings would emit a warning to the effect of "unknown type 'Foo';
  712. representing as first known parent type 'Bar'".  However, for some
  713. types, such as GtkStyle or GdkGC, the actual object returned is an
  714. instance of a child type of a private implementation (e.g., a theme
  715. engine ("BlueCurveStyle") or gdk backend ("GdkGCX11")); we neither can
  716. nor should have registered names for these types.  Therefore, it is
  717. possible to tell the bindings not to warn about these unregistered
  718. subclasses, and simply represent them as the parent type.
  719.  
  720. With 1.12x, the bindings will automatically register unknown classes
  721. into the namespace Glib::Object::_Unregistered to avoid possible
  722. breakage resulting from unknown ancestors of known children.  To
  723. preserve the old registered-as-unregistered behavior, the value
  724. installed by this function is used to prevent the _Unregistered mapping
  725. for such private backend classes.
  726.  
  727.  
  728. Note: this assumes I<gtype> has already been registered with
  729. gperl_register_object().
  730.  
  731. =cut
  732.  
  733. =item const char * gperl_object_package_from_type (GType gtype)
  734.  
  735. Get the package corresponding to I<gtype>.  If I<gtype> is not a GObject
  736. or GInterface, returns NULL.  If I<gtype> is not registered to a package
  737. name, a new name of the form C<Glib::Object::_Unregistered::$c_type_name>
  738. will be created, used to register the class, and then returned.
  739.  
  740. =cut
  741.  
  742. =item HV * gperl_object_stash_from_type (GType gtype)
  743.  
  744. Get the stash corresponding to I<gtype>; returns NULL if I<gtype> is
  745. not registered.  The stash is useful for C<bless>ing.
  746.  
  747. =cut
  748.  
  749. =item GType gperl_object_type_from_package (const char * package)
  750.  
  751. Inverse of gperl_object_package_from_type(),  returns 0 if I<package>
  752. is not registered.
  753.  
  754. =cut
  755.  
  756. =item SV * gperl_new_object (GObject * object, gboolean own)
  757.  
  758. Use this function to get the perl part of a GObject.  If I<object>
  759. has never been seen by perl before, a new, empty perl object will
  760. be created and added to a private key under I<object>'s qdata.  If
  761. I<object> already has a perl part, a new reference to it will be
  762. created. The gobject + perl object together form a combined object that
  763. is properly refcounted, i.e. both parts will stay alive as long as at
  764. least one of them is alive, and only when both perl object and gobject are
  765. no longer referenced will both be freed.
  766.  
  767. The perl object will be blessed into the package corresponding to the GType
  768. returned by calling G_OBJECT_TYPE() on I<object>; if that class has not
  769. been registered via gperl_register_object(), this function will emit a
  770. warning to that effect (with warn()), and attempt to bless it into the
  771. first known class in the object's ancestry.  Since Glib::Object is
  772. already registered, you'll get a Glib::Object if you are lazy, and thus
  773. this function can fail only if I<object> isn't descended from GObject,
  774. in which case it croaks.  (In reality, if you pass a non-GObject to this
  775. function, you'll be lucky if you don't get a segfault, as there's not
  776. really a way to trap that.)  In practice these warnings can be unavoidable,
  777. so you can use gperl_object_set_no_warn_unreg_subclass() to quell them
  778. on a class-by-class basis.
  779.  
  780. However, when perl code is calling a GObject constructor (any function
  781. which returns a new GObject), call gperl_new_object() with I<own> set to
  782. %TRUE; this will cause the first matching sink function to be called
  783. on the GObject to claim ownership of that object, so that it will be
  784. destroyed when the perl object goes out of scope. The default sink func
  785. is g_object_unref(); other types should supply the proper function;
  786. e.g., GtkObject should use gtk_object_sink() here.
  787.  
  788. Returns the blessed perl object, or #&PL_sv_undef if object was #NULL.
  789.  
  790. =cut
  791.  
  792. =item GObject * gperl_get_object (SV * sv)
  793.  
  794. retrieve the GObject pointer from a Perl object.  Returns NULL if I<sv> is not
  795. linked to a GObject.
  796.  
  797. Note, this one is not safe -- in general you want to use
  798. gperl_get_object_check().
  799.  
  800. =cut
  801.  
  802. =item GObject * gperl_get_object_check (SV * sv, GType gtype);
  803.  
  804. croaks if I<sv> is undef or is not blessed into the package corresponding 
  805. to I<gtype>.  use this for bringing parameters into xsubs from perl.
  806. Returns the same as gperl_get_object() (provided it doesn't croak first).
  807.  
  808. =cut
  809.  
  810. =item SV * gperl_object_check_type (SV * sv, GType gtype)
  811.  
  812. Essentially the same as gperl_get_object_check().
  813.  
  814. This croaks if the types aren't compatible.
  815.  
  816. =cut
  817.  
  818. =item typedef GObject GObject_noinc
  819.  
  820. =item typedef GObject GObject_ornull
  821.  
  822. =item newSVGObject(obj)
  823.  
  824. =item newSVGObject_noinc(obj)
  825.  
  826. =item SvGObject(sv)
  827.  
  828. =item SvGObject_ornull(sv)
  829.  
  830.  
  831. =back
  832.  
  833. =cut
  834.  
  835. =head2 GValue
  836.  
  837. GValue is GLib's generic value container, and it is because of GValue that the
  838. run time type handling of GObject parameters and GClosure marshaling can
  839. function, and most usages of these functions will be from those two points.
  840.  
  841. Client code will run into uses for gperl_sv_from_value() and
  842. gperl_value_from_sv() when trying to convert lists of parameters into GValue
  843. arrays and the like.
  844.  
  845. =over
  846.  
  847. =cut
  848.  
  849. =item gboolean gperl_value_from_sv (GValue * value, SV * sv)
  850.  
  851. set a I<value> from a whatever is in I<sv>.  I<value> must be initialized 
  852. so the code knows what kind of value to coerce out of I<sv>.
  853.  
  854. Return value is always TRUE; if the code knows how to perform the conversion,
  855. it croaks.  (The return value is for backward compatibility.) In reality,
  856. this really ought to always succeed; a failed conversion should be considered
  857. a bug or unimplemented code!
  858.  
  859. =cut
  860.  
  861. =item SV * gperl_sv_from_value (const GValue * value)
  862.  
  863. Coerce whatever is in I<value> into a perl scalar and return it.
  864.  
  865. Croaks if the code doesn't know how to perform the conversion.
  866.  
  867. =cut
  868.  
  869. =back
  870.  
  871. =cut
  872.  
  873. =head2 GClosure / GPerlClosure
  874.  
  875. GPerlClosure is a wrapper around the gobject library's GClosure with
  876. special handling for marshalling perl subroutines as callbacks.
  877. This is specially tuned for use with GSignal and stuff like io watch,
  878. timeout, and idle handlers.
  879.  
  880. For generic callback functions, which need parameters but do not get
  881. registered with the type system, this is sometimes overkill.  See
  882. GPerlCallback, below.
  883.  
  884. =over
  885.  
  886. =cut
  887.  
  888. =item GClosure * gperl_closure_new (SV * callback, SV * data, gboolean swap)
  889.  
  890. Create and return a new GPerlClosure.  I<callback> and I<data> will be copied
  891. for storage; I<callback> must not be NULL.  If I<swap> is TRUE, I<data> will be
  892. swapped with the instance during invocation (this is used to implement
  893. g_signal_connect_swapped()).
  894.  
  895. If compiled under a thread-enabled perl, the closure will be created and
  896. marshaled in such a way as to ensure that the same interpreter which created
  897. the closure will be used to invoke it.
  898.  
  899. =cut
  900.  
  901. =item GClosure * gperl_closure_new_with_marshaller (SV * callback, SV * data, gboolean swap, GClosureMarshal marshaller)
  902.  
  903. Like C<gperl_closure_new>, but uses a caller-supplied marshaller.  This is
  904. provided for use in those sticky circumstances when you just can't do it 
  905. any other way; in general, you want to use the default marshaller, which you
  906. get if you provide NULL for I<marshaller>.
  907.  
  908. If you use you own marshaller, you need to take care of everything yourself,
  909. including swapping the instance and data if C<GPERL_CLOSURE_SWAP_DATA
  910. (closure)> is true, calling C<gperl_run_exception_handlers> if ERRSV is true
  911. after invoking the perl sub, and ensuring that you properly use the
  912. C<marshal_data> parameter as the perl interpreter when PERL_IMPLICIT_CONTEXT is
  913. defined.  See the implementation of the default marshaller,
  914. C<gperl_closure_marshal>, in Glib/GClosure.xs for inspiration.
  915.  
  916. =cut
  917.  
  918. =back
  919.  
  920. =head2 GPerlCallback
  921.  
  922. generic callback functions usually get invoked directly, and are not passed
  923. parameter lists as GValues.  we could very easily wrap up such generic
  924. callbacks with something that converts the parameters to GValues and then
  925. channels everything through GClosure, but this has two problems:  1) the above
  926. implementation of GClosure is tuned to marshalling signal handlers, which
  927. always have an instance object, and 2) it's more work than is strictly
  928. necessary.
  929.  
  930. additionally, generic callbacks aren't always kind to the GClosure paradigm.
  931.  
  932. so, here's GPerlCallback, which is designed specifically to run generic
  933. callback functions.  it reads parameters off the C stack and converts them into
  934. parameters on the perl stack.  (it uses the GValue to/from SV mechanism to do
  935. so, but doesn't allocate any temps on the heap.)  the callback object itself
  936. stores the parameter type list.
  937.  
  938. unfortunately, since the data element is always last, but the number of
  939. arguments is not known until we have the callback object, we can't pass
  940. gperl_callback_invoke directly to functions requiring a callback; you'll have
  941. to write a proxy callback which calls gperl_callback_invoke.
  942.  
  943. =over
  944.  
  945. =item GPerlCallback * gperl_callback_new (SV * func, SV * data, gint n_params, GType param_types[], GType return_type)
  946.  
  947. Create and return a new GPerlCallback; use gperl_callback_destroy when you are
  948. finished with it.
  949.  
  950. I<func>: perl subroutine to call.  this SV will be copied, so don't worry about
  951. reference counts.  must B<not> be #NULL.
  952.  
  953. I<data>: scalar to pass to I<func> in addition to all other arguments.  the SV
  954. will be copied, so don't worry about reference counts.  may be #NULL.
  955.  
  956. I<n_params>: the number of elements in I<param_types>.
  957.  
  958. I<param_types>: the #GType of each argument that should be passed from the
  959. invocation to I<func>.  may be #NULL if I<n_params> is zero, otherwise it must
  960. be I<n_params> elements long or nasty things will happen.  this array will be
  961. copied; see gperl_callback_invoke() for how it is used.
  962.  
  963. I<return_type>: the #GType of the return value, or 0 if the function has void
  964. return.
  965.  
  966. =cut
  967.  
  968. =item void gperl_callback_destroy (GPerlCallback * callback)
  969.  
  970. Dispose of I<callback>.
  971.  
  972. =cut
  973.  
  974. =item void gperl_callback_invoke (GPerlCallback * callback, GValue * return_value, ...)
  975.  
  976. Marshall the variadic parameters according to I<callback>'s param_types, and
  977. then invoke I<callback>'s subroutine in scalar context, or void context if the
  978. return type is G_TYPE_VOID.  If I<return_value> is not NULL, then value
  979. returned (if any) will be copied into I<return_value>.
  980.  
  981. A typical callback handler would look like this:
  982.  
  983.   static gint
  984.   real_c_callback (Foo * f, Bar * b, int a, gpointer data)
  985.   {
  986.           GPerlCallback * callback = (GPerlCallback*)data;
  987.           GValue return_value = {0,};
  988.           gint retval;
  989.           g_value_init (&return_value, callback->return_type);
  990.           gperl_callback_invoke (callback, &return_value,
  991.                                  f, b, a);
  992.           retval = g_value_get_int (&return_value);
  993.           g_value_unset (&return_value);
  994.           return retval;
  995.   }
  996.  
  997.  
  998.  
  999. =cut
  1000.  
  1001. =back
  1002.  
  1003. =head2 Exception Handling
  1004.  
  1005. Like Event, Tk, and most other callback-using, event-based perl modules,
  1006. Glib traps exceptions that happen in callbacks.  To enable your code to
  1007. do something about these exceptions, Glib stores a list of exception
  1008. handlers which will be called on the trapped exceptions.  This is
  1009. completely distinct from the $SIG{__DIE__} mechanism provided by Perl
  1010. itself, for various reasons (not the least of which is that the Perl
  1011. docs and source code say that $SIG{__DIE__} is intended for running as
  1012. the program is about to exit, and other behaviors may be removed in the
  1013. future (apparently a source of much debate on p5p)).
  1014.  
  1015. =over
  1016.  
  1017. =cut
  1018.  
  1019. =item int gperl_install_exception_handler (GClosure * closure)
  1020.  
  1021. Install a GClosure to be executed when gperl_closure_invoke() traps an
  1022. exception.  The closure should return boolean (TRUE if the handler should
  1023. remain installed) and expect to receive a perl scalar.  This scalar will be
  1024. a private copy of ERRSV ($@) which the handler can mangle to its heart's
  1025. content.
  1026.  
  1027. The return value is an integer id tag that may be passed to
  1028. gperl_removed_exception_handler().
  1029.  
  1030. =cut
  1031.  
  1032. =item void gperl_remove_exception_handler (guint tag)
  1033.  
  1034. Remove the exception handler identified by I<tag>, as returned by
  1035. gperl_install_exception_handler().  If I<tag> cannot be found, this
  1036. does nothing.
  1037.  
  1038. WARNING:  this function locks a global data structure, so do NOT call
  1039. it recursively.  also, calling this from within an exception handler will
  1040. result in a deadlock situation.  if you want to remove your handler just
  1041. have it return FALSE.
  1042.  
  1043. =cut
  1044.  
  1045. =item void gperl_run_exception_handlers (void)
  1046.  
  1047. Invoke whatever exception handlers are installed.  You will need this if
  1048. you have written a custom marshaler.  Uses the value of the global ERRSV.
  1049.  
  1050. =cut
  1051.  
  1052. =back
  1053.  
  1054. =cut
  1055.  
  1056. =head2 GSignal
  1057.  
  1058. =over
  1059.  
  1060. =cut
  1061.  
  1062. =item void gperl_signal_set_marshaller_for (GType instance_type, char * detailed_signal, GClosureMarshal marshaller)
  1063.  
  1064. You need this function only in rare cases, usually as workarounds for bad
  1065. signal parameter types or to implement writable arguments.  Use the given
  1066. I<marshaller> to marshal all handlers for I<detailed_signal> on
  1067. I<instance_type>.  C<gperl_signal_connect> will look for marshallers
  1068. registered here, and apply them to the GPerlClosure it creates for the given
  1069. callback being connected.
  1070.  
  1071. Use the helper macros in gperl_marshal.h to help write your marshaller
  1072. function.  That header, which is installed with the Glib module but not
  1073. #included through gperl.h, includes commentary and examples which you
  1074. should follow closely to avoid nasty bugs.  Use the Source, Luke.
  1075.  
  1076. WARNING: Bend over backwards and turn your head around 720 degrees before
  1077. attempting to write a GPerlClosure marshaller without using the macros in
  1078. gperl_marshal.h.  If you absolutely cannot use those macros, be certain to
  1079. understand what those macros do so you can get the semantics correct, and
  1080. keep your code synchronized with them, or you may miss very important
  1081. bugfixes.
  1082.  
  1083. =cut
  1084.  
  1085. =item gulong gperl_signal_connect (SV * instance, char * detailed_signal, SV * callback, SV * data, GConnectFlags flags)
  1086.  
  1087. The actual workhorse behind GObject::signal_connect, the binding for
  1088. g_signal_connect, for use from within XS.  This creates a C<GPerlClosure>
  1089. wrapper for the given I<callback> and I<data>, and connects that closure to the
  1090. signal named I<detailed_signal> on the given GObject I<instance>.  This is only
  1091. good for named signals.  I<flags> is the same as for g_signal_connect().
  1092. I<data> may be NULL, but I<callback> must not be.
  1093.  
  1094. Returns the id of the installed callback.
  1095.  
  1096. =cut
  1097.  
  1098. =back
  1099.  
  1100. =cut
  1101.  
  1102.  
  1103. =head1 SEE ALSO
  1104.  
  1105. perlapi(1), perlguts(1), GLib Reference Manual, Glib(3pm), Glib::devel(3pm).
  1106.  
  1107. =head1 AUTHORS
  1108.  
  1109. This file was automatically generated from the source code of the Glib module,
  1110. which is maintained by the gtk2-perl team.
  1111.  
  1112. =head1 LICENSE
  1113.  
  1114. Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
  1115. full list)
  1116.  
  1117. This library is free software; you can redistribute it and/or modify it under
  1118. the terms of the GNU Library General Public License as published by the Free
  1119. Software Foundation; either version 2.1 of the License, or (at your option) any
  1120. later version.
  1121.  
  1122. This library is distributed in the hope that it will be useful, but WITHOUT ANY
  1123. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1124. PARTICULAR PURPOSE.  See the GNU Library General Public License for more
  1125. details.
  1126.  
  1127. You should have received a copy of the GNU Library General Public License along
  1128. with this library; if not, write to the Free Software Foundation, Inc., 59
  1129. Temple Place - Suite 330, Boston, MA  02111-1307  USA.
  1130.  
  1131. =cut
  1132.